package hsp.admin.api;

import lombok.Getter;
import lombok.ToString;

@Getter
@ToString
public class ApiResult<T> {

    private int code;
    private String message;
    private T data;

    public ApiResult<T> setCode(int code) {
        this.code = code;
        return this;
    }

    public ApiResult<T> setMessage(String message) {
        this.message = message;
        return this;
    }

    public ApiResult<T> setData(T data) {
        this.data = data;
        return this;
    }

    public static <T> ApiResult<T> success(){
        return new ApiResult<T>().setCode(ApiCode.Success.getCode()).setMessage(ApiCode.Success.getMsg());
    }

    public static <T> ApiResult<T> success(String msg){
        return new ApiResult<T>().setCode(ApiCode.Success.getCode()).setMessage(msg);
    }

    public static <T> ApiResult<T> success(T data){
        return new ApiResult<T>().setCode(ApiCode.Success.getCode()).setMessage(ApiCode.Success.getMsg()).setData(data);
    }

    public static <T> ApiResult<T> success(T data, String msg){
        return new ApiResult<T>().setCode(ApiCode.Success.getCode()).setMessage(msg).setData(data);
    }

    public static <T> ApiResult<T> failed(ApiCode apiCode) {
        return new ApiResult<T>().setCode(apiCode.getCode()).setMessage(apiCode.getMsg());
    }

    public static <T> ApiResult<T> failed(String msg) {
        return new ApiResult<T>().setCode(ApiCode.Failed.getCode()).setMessage(msg);
    }

}
